﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Microsoft.Practices.Unity;
using WDA.Core;
using System.Threading;
using WDA.Public;
using System.ServiceModel.Channels;

namespace Sample
{
   [ServiceContract]
   public interface IParserService
   {
      [OperationContract]
      int ParseInt(string value);
      [OperationContract]
      double ParseDouble(string value);
   }
   [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
   public class ParserService : IParserService
   {
      [Dependency(WDA.Core.WDAContainerNames.InternalContainerName)]
      public IUnityContainer Container { get; set; }

      [Dependency(WDA.Core.WDAContainerNames.PersistentInternalContainerName)]
      public IUnityContainer PersistentContainer { get; set; }      
		
		private static Logger _log = new Logger("Sample.ConverterService");

      #region IParserService Members
      public int ParseInt(string value)
      {
			IResponseTimeValue respTime = Container.Resolve<IResponseTimeValue>();
			//_log.WriteInfo("Parsing {0} to Int32.", value);
         IServices srv = PersistentContainer.Resolve<IServices>();         
         srv.Communicate<IPrinterService>(proxy => proxy.Print(string.Format("Parsing {0} to Int32.", value)));
			Thread.Sleep(respTime.Milliseconds);
         return int.Parse(value);
      }
      public double ParseDouble(string value)
      {
			IResponseTimeValue respTime = Container.Resolve<IResponseTimeValue>();
			//_log.WriteInfo("Parsing {0} to Double.", value);
			Thread.Sleep(respTime.Milliseconds);
         return double.Parse(value);
      }
      #endregion
   }
}
